package com.cat.dataStructure;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/bulb-switcher/
 * @create 2025/8/24 16:26
 * @since JDK17
 */

public class Solution53 {
    public static int bulbSwitch(int n) {
        int[] nums = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j += i) {
                nums[j] = 1 - nums[j];
            }
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            ans += nums[i];
        }



        return ans;
    }
    public static int bulbSwitch02(int n) {
        for (long i = 1, j = 3; true; i++, j += 1 + 2 * i) {
            if (j >= n) {
                return ((int) i);
            }
        }
    }

    // 3 5 7 9
    public static void main(String[] args) {
        for (int i = 1; i <= 30; i++) {
            System.out.println(i + " " + bulbSwitch(i));
            System.out.println(i + " " + bulbSwitch02(i));

        }
    }
}
